Fix all tests from the update to rust master
authorAlex Crichton <alex@alexcrichton.com>
Mon, 9 Mar 2015 19:07:35 +0000 (12:07 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 9 Mar 2015 20:51:11 +0000 (13:51 -0700)
Cargo.lock
Cargo.toml
src/bin/cargo.rs
tests/support/paths.rs
tests/support/registry.rs
tests/test_cargo_build_auth.rs
tests/test_cargo_compile.rs
tests/test_cargo_cross_compile.rs
tests/test_cargo_new.rs
tests/test_cargo_registry.rs
tests/tests.rs

index 5cef0e23d7d2eb7907dc03c2d3864b25522225b3..1285b0254b02fa7af273e4e2825b4374809f1dbb 100644 (file)
@@ -18,6 +18,7 @@ dependencies = [
  "rustc-serialize 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "semver 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
  "tar 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tempdir 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "term 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
  "threadpool 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -218,6 +219,15 @@ name = "pnacl-build-helper"
 version = "1.3.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
+[[package]]
+name = "rand"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "regex"
 version = "0.1.18"
@@ -246,6 +256,14 @@ name = "tar"
 version = "0.2.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
+[[package]]
+name = "tempdir"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rand 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "term"
 version = "0.1.13"
index 012daed8e5562535ce81a0c2a4bf9b301af5bc42..8e9ae24f8a19dd4243468794b03f2b2ddb8a16a7 100644 (file)
@@ -28,20 +28,16 @@ term = "0.1.13"
 regex = "0.1.18"
 threadpool = "0.1.1"
 libc = "0.1.2"
+registry = { path = "src/registry" }
 
-[target.i686-pc-windows-gnu.dependencies]
-winapi = "0.1"
-advapi32-sys = "*"
+[target.i686-pc-windows-gnu]
+dependencies = { winapi = "0.1", advapi32-sys = "*" }
+[target.x86_64-pc-windows-gnu]
+dependencies = { winapi = "0.1", advapi32-sys = "*" }
 
-[target.x86_64-pc-windows-gnu.dependencies]
-winapi = "0.1"
-advapi32-sys = "*"
-
-[dev-dependencies.hamcrest]
-git = "https://github.com/carllerche/hamcrest-rust.git"
-
-[dependencies.registry]
-path = "src/registry"
+[dev-dependencies]
+tempdir = "0.3"
+hamcrest = { git = "https://github.com/carllerche/hamcrest-rust.git" }
 
 [[bin]]
 name = "cargo"
@@ -50,9 +46,6 @@ doc = false
 
 [[test]]
 name = "tests"
-[[bench]]
-name = "tests"
-path = "tests/tests.rs"
 
 [[test]]
 name = "resolve"
index 7707762cd6a250f3417b27fa65ad84a4ed7bf756..733d0dd1cf2a8de0e1cee56079d3e2d4510fc9de 100644 (file)
@@ -101,39 +101,54 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
         return Ok(None)
     }
 
-    let (mut args, command) = match &flags.arg_command[..] {
+    let args = match &flags.arg_command[..] {
+        // For the commands `cargo` and `cargo help`, re-execute ourselves as
+        // `cargo -h` so we can go through the normal process of printing the
+        // help message.
         "" | "help" if flags.arg_args.len() == 0 => {
             config.shell().set_verbose(true);
-            let args = &["foo".to_string(), "-h".to_string()];
+            let args = &["cargo".to_string(), "-h".to_string()];
             let r = cargo::call_main_without_stdin(execute, config, USAGE, args,
                                                    false);
-            cargo::process_executed(r, &mut **config.shell());
+            cargo::process_executed(r, &mut config.shell());
             return Ok(None)
         }
+
+        // For `cargo help -h` and `cargo help --help`, print out the help
+        // message for `cargo help`
         "help" if flags.arg_args[0] == "-h" ||
-                  flags.arg_args[0] == "--help" =>
-            (flags.arg_args, "help"),
-        "help" => (vec!["-h".to_string()], &flags.arg_args[0][..]),
-        s => (flags.arg_args.clone(), s),
+                  flags.arg_args[0] == "--help" => {
+            vec!["cargo".to_string(), "help".to_string(), "help".to_string()]
+        }
+
+        // For `cargo help foo`, print out the usage message for the specified
+        // subcommand by executing the command with the `-h` flag.
+        "help" => {
+            vec!["cargo".to_string(), "help".to_string(),
+                 flags.arg_args[0].clone()]
+        }
+
+        // For all other invocations, we're of the form `cargo foo args...`. We
+        // use the exact environment arguments to preserve tokens like `--` for
+        // example.
+        _ => env::args().collect(),
     };
-    args.insert(0, command.to_string());
-    args.insert(0, "foo".to_string());
 
     macro_rules! cmd{ ($name:ident) => (
-        if command == stringify!($name).replace("_", "-") {
+        if args[1] == stringify!($name).replace("_", "-") {
             mod $name;
             config.shell().set_verbose(true);
             let r = cargo::call_main_without_stdin($name::execute, config,
                                                    $name::USAGE,
                                                    &args,
                                                    false);
-            cargo::process_executed(r, &mut **config.shell());
+            cargo::process_executed(r, &mut config.shell());
             return Ok(None)
         }
     ) }
     each_subcommand!(cmd);
 
-    execute_subcommand(&command, &args, &mut config.shell());
+    execute_subcommand(&args[1], &args, &mut config.shell());
     Ok(None)
 }
 
@@ -230,7 +245,7 @@ fn is_executable(path: &Path) -> bool {
 }
 #[cfg(windows)]
 fn is_executable(path: &Path) -> bool {
-    path.is_file()
+    fs::metadata(path).map(|m| m.is_file()) == Ok(true)
 }
 
 /// Get `Command` to run given command.
index 8cbd2406372f221b4e98f924c458593515faa3a8..491990c0a0ac34f348fb947770120b46d4761ae2 100644 (file)
@@ -1,7 +1,7 @@
 use std::env;
 use std::fs;
 use std::io::prelude::*;
-use std::io;
+use std::io::{self, ErrorKind};
 use std::path::{Path, PathBuf};
 use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
 
@@ -32,7 +32,29 @@ impl CargoPathExt for Path {
      */
     fn rm_rf(&self) -> io::Result<()> {
         if self.exists() {
-            fs::remove_dir_all(self)
+            for file in fs::read_dir(self).unwrap() {
+                let file = try!(file).path();
+
+                if file.is_dir() {
+                    try!(file.rm_rf());
+                } else {
+                    // On windows we can't remove a readonly file, and git will
+                    // often clone files as readonly. As a result, we have some
+                    // special logic to remove readonly files on windows.
+                    match fs::remove_file(&file) {
+                        Ok(()) => {}
+                        Err(ref e) if cfg!(windows) &&
+                                      e.kind() == ErrorKind::PermissionDenied => {
+                            let mut p = file.metadata().unwrap().permissions();
+                            p.set_readonly(false);
+                            fs::set_permissions(&file, p).unwrap();
+                            try!(fs::remove_file(&file));
+                        }
+                        Err(e) => return Err(e)
+                    }
+                }
+            }
+            fs::remove_dir(self)
         } else {
             Ok(())
         }
index ec8fa0ab3c6ddf3542100e2b21c9d0c071af7e53..9cb06dfaa362895ec031851f9832aa66b2ad0286 100644 (file)
@@ -88,8 +88,8 @@ pub fn mock_pkg_yank(name: &str, version: &str, deps: &[(&str, &str, &str)],
     let file = match name.len() {
         1 => format!("1/{}", name),
         2 => format!("2/{}", name),
-        3 => format!("3/{}/{}", name.slice_to(1), name),
-        _ => format!("{}/{}/{}", name.slice(0, 2), name.slice(2, 4), name),
+        3 => format!("3/{}/{}", &name[..1], name),
+        _ => format!("{}/{}/{}", &name[0..2], &name[2..4], name),
     };
     publish(file.as_slice(), line.as_slice());
 }
index 1c7705167a068cb152ba2817e402fc5adf682312..eaa495f3e5ff0f2e59978f77b03e61097f63db14 100644 (file)
@@ -1,6 +1,7 @@
 use std::collections::HashSet;
-use std::old_io::net::tcp::TcpAcceptor;
-use std::old_io::{TcpListener, Listener, Acceptor, BufferedStream};
+use std::io::BufStream;
+use std::io::prelude::*;
+use std::net::TcpListener;
 use std::thread;
 use git2;
 
@@ -11,23 +12,12 @@ use hamcrest::assert_that;
 fn setup() {
 }
 
-struct Closer { a: TcpAcceptor }
-
-impl Drop for Closer {
-    fn drop(&mut self) {
-        let _ = self.a.close_accept();
-    }
-}
-
 // Test that HTTP auth is offered from `credential.helper`
 test!(http_auth_offered {
-    let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
-    let addr = listener.socket_name().unwrap();
-    let mut a = listener.listen().unwrap();
-    let a2 = a.clone();
-    let _c = Closer { a: a2 };
+    let a = TcpListener::bind("127.0.0.1:0").unwrap();
+    let addr = a.socket_addr().unwrap();
 
-    fn headers<R: Buffer>(rdr: &mut R) -> HashSet<String> {
+    fn headers(rdr: &mut BufRead) -> HashSet<String> {
         let valid = ["GET", "Authorization", "Accept", "User-Agent"];
         rdr.lines().map(|s| s.unwrap())
            .take_while(|s| s.len() > 2)
@@ -39,7 +29,7 @@ test!(http_auth_offered {
     }
 
     let t = thread::spawn(move|| {
-        let mut s = BufferedStream::new(a.accept().unwrap());
+        let mut s = BufStream::new(a.accept().unwrap().0);
         let req = headers(&mut s);
         s.write_all(b"\
             HTTP/1.1 401 Unauthorized\r\n\
@@ -53,7 +43,7 @@ test!(http_auth_offered {
         ].into_iter().map(|s| s.to_string()).collect());
         drop(s);
 
-        let mut s = BufferedStream::new(a.accept().unwrap());
+        let mut s = BufStream::new(a.accept().unwrap().0);
         let req = headers(&mut s);
         s.write_all(b"\
             HTTP/1.1 401 Unauthorized\r\n\
@@ -91,7 +81,7 @@ test!(http_auth_offered {
                    script.display().to_string().as_slice()).unwrap();
 
     let p = project("foo")
-        .file("Cargo.toml", format!(r#"
+        .file("Cargo.toml", &format!(r#"
             [project]
             name = "foo"
             version = "0.0.1"
@@ -99,7 +89,7 @@ test!(http_auth_offered {
 
             [dependencies.bar]
             git = "http://127.0.0.1:{}/foo/bar"
-        "#, addr.port).as_slice())
+        "#, addr.port()))
         .file("src/main.rs", "");
 
     assert_that(p.cargo_process("build").arg("-v"),
@@ -125,17 +115,14 @@ Caused by:
 
 // Boy, sure would be nice to have a TLS implementation in rust!
 test!(https_something_happens {
-    let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
-    let addr = listener.socket_name().unwrap();
-    let mut a = listener.listen().unwrap();
-    let a2 = a.clone();
-    let _c = Closer { a: a2 };
+    let a = TcpListener::bind("127.0.0.1:0").unwrap();
+    let addr = a.socket_addr().unwrap();
     let t = thread::spawn(move|| {
         drop(a.accept().unwrap());
     });
 
     let p = project("foo")
-        .file("Cargo.toml", format!(r#"
+        .file("Cargo.toml", &format!(r#"
             [project]
             name = "foo"
             version = "0.0.1"
@@ -143,7 +130,7 @@ test!(https_something_happens {
 
             [dependencies.bar]
             git = "https://127.0.0.1:{}/foo/bar"
-        "#, addr.port).as_slice())
+        "#, addr.port()))
         .file("src/main.rs", "");
 
     assert_that(p.cargo_process("build").arg("-v"),
@@ -175,11 +162,8 @@ Caused by:
 
 // Boy, sure would be nice to have an SSH implementation in rust!
 test!(ssh_something_happens {
-    let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
-    let addr = listener.socket_name().unwrap();
-    let mut a = listener.listen().unwrap();
-    let a2 = a.clone();
-    let _c = Closer { a: a2 };
+    let a = TcpListener::bind("127.0.0.1:0").unwrap();
+    let addr = a.socket_addr().unwrap();
     let t = thread::spawn(move|| {
         drop(a.accept().unwrap());
     });
@@ -193,7 +177,7 @@ test!(ssh_something_happens {
 
             [dependencies.bar]
             git = "ssh://127.0.0.1:{}/foo/bar"
-        "#, addr.port).as_slice())
+        "#, addr.port()).as_slice())
         .file("src/main.rs", "");
 
     assert_that(p.cargo_process("build").arg("-v"),
index 3fb658dbb8056242fca4f7050d1c1f577518a665..253f81812b868fc7e42a7118304e114ce46b2d68 100644 (file)
@@ -1,6 +1,7 @@
 use std::env;
-use std::fs::{self, TempDir, File};
+use std::fs::{self, File};
 use std::io::prelude::*;
+use tempdir::TempDir;
 
 use support::{project, execs, main_file, basic_bin_manifest};
 use support::{COMPILING, RUNNING, ProjectBuilder};
index fcb67755823586585d719fecb3bce157d8449606..aaf38bfb94a05777844cff7200bcd5d0c9558274 100644 (file)
@@ -142,7 +142,7 @@ test!(plugin_deps {
             use rustc::plugin::Registry;
             use syntax::ast::TokenTree;
             use syntax::codemap::Span;
-            use syntax::ext::base::{ExtCtxt, MacExpr, MacResult};
+            use syntax::ext::base::{ExtCtxt, MacEager, MacResult};
 
             #[plugin_registrar]
             pub fn foo(reg: &mut Registry) {
@@ -151,7 +151,7 @@ test!(plugin_deps {
 
             fn expand_bar(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
                           -> Box<MacResult + 'static> {
-                MacExpr::new(quote_expr!(cx, 1))
+                MacEager::expr(quote_expr!(cx, 1))
             }
         "#);
     let baz = project("baz")
@@ -222,7 +222,7 @@ test!(plugin_to_the_max {
             use rustc::plugin::Registry;
             use syntax::ast::TokenTree;
             use syntax::codemap::Span;
-            use syntax::ext::base::{ExtCtxt, MacExpr, MacResult};
+            use syntax::ext::base::{ExtCtxt, MacEager, MacResult};
 
             #[plugin_registrar]
             pub fn foo(reg: &mut Registry) {
@@ -231,7 +231,7 @@ test!(plugin_to_the_max {
 
             fn expand_bar(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
                           -> Box<MacResult + 'static> {
-                MacExpr::new(quote_expr!(cx, baz::baz()))
+                MacEager::expr(quote_expr!(cx, baz::baz()))
             }
         "#);
     let baz = project("baz")
index ef873526a7b6e5f89a9eec6bdbca3b71ce2f3be6..d2bfd438dcc3a53d721376268a90518f43f5dffc 100644 (file)
@@ -1,6 +1,7 @@
-use std::fs::{self, File, TempDir};
+use std::fs::{self, File};
 use std::io::prelude::*;
 use std::env;
+use tempdir::TempDir;
 
 use support::{execs, paths, cargo_dir};
 use hamcrest::{assert_that, existing_file, existing_dir, is_not};
index 730b314142f10b33b6a9d1500a559366508991cf..47ae6bd256322db9976624059f5cedd2503590b4 100644 (file)
@@ -441,7 +441,7 @@ test!(update_with_lockfile_if_packages_missing {
                 execs().with_status(0));
     p.root().move_into_the_past().unwrap();
 
-    fs::remove_dir_all(&paths::home().join(".cargo/registry")).unwrap();
+    paths::home().join(".cargo/registry").rm_rf().unwrap();
     assert_that(p.cargo("build"),
                 execs().with_status(0).with_stdout(format!("\
 {updating} registry `[..]`
@@ -470,7 +470,7 @@ test!(update_lockfile {
 
     r::mock_pkg("bar", "0.0.2", &[]);
     r::mock_pkg("bar", "0.0.3", &[]);
-    fs::remove_dir_all(&paths::home().join(".cargo/registry")).unwrap();
+    paths::home().join(".cargo/registry").rm_rf().unwrap();
     println!("0.0.2 update");
     assert_that(p.cargo("update")
                  .arg("-p").arg("bar").arg("--precise").arg("0.0.2"),
index d526e975199acf64e101d5b5a170dece19989fa1..356690d860cfadb88a836ead05b4904f2e16e51d 100644 (file)
@@ -1,5 +1,5 @@
-#![feature(core, io, old_io, os, old_path)]
-#![feature(std_misc, io, path, fs, tempdir)]
+#![feature(core, io, old_io, old_path)]
+#![feature(std_misc, io, path, fs, net, path_ext, fs_time, fs_walk)]
 
 extern crate "rustc-serialize" as serialize;
 extern crate cargo;
@@ -9,6 +9,7 @@ extern crate hamcrest;
 extern crate tar;
 extern crate term;
 extern crate url;
+extern crate tempdir;
 
 #[macro_use]
 extern crate log;